package top.frsf.rpc.loadbalance.impl;

import top.frsf.rpc.entity.ServiceInstance;
import top.frsf.rpc.enums.LoadBalanceEnum;
import top.frsf.rpc.loadbalance.LoadBalance;

import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @author He Kuntao
 * @since 2025/7/18 11:02
 */
public class RandomLoadBalance implements LoadBalance {
    @Override
    public ServiceInstance select(List<ServiceInstance> instances) {
        // 随机选择
        int index = ThreadLocalRandom.current().nextInt(instances.size());
        return instances.get(index);
    }

    @Override
    public LoadBalanceEnum getLoadBalanceEnum() {
        return LoadBalanceEnum.RANDOM;
    }
}
